#ifndef CAICLIENT_H
#define CAICLIENT_H

#include <QObject>
#include <QQuickItem>
#include <QNetworkAccessManager>
#include <QtNetwork>
//#include "cresult.h"
class CAIClient:public QObject
{
    Q_OBJECT
public:
    CAIClient();
private:
    QString post_json(QString path, QByteArray &body);
    QString get_json(QString path, QByteArray &body);
    QString post_multipart(QString path, QHttpMultiPart &body);
public slots:
    QString login(QString suser, QString spassword);
    QString get_reset_validate_code(QString suser);
    QString reset_password(QString suser, QString svalidate_code, QString spassword);
    QString get_register_validate_code(QString suser);
    QString register_user(QString suser, QString svalidate_code, QString spassword);
    QString reset_password_by_auth(QString suser, QString spassword_old, QString spassword_new);

    QString list_model();
    QString list_model_grant();
    QString list_model_public();
    QString list_model_available();
    QString get_model(QString smodel_id);
    QString get_model_by_version(QString smodel_id, QString sversion);
    QString edit_model(QString smodel_id, QString smodel_name, QString smodel_class, QString sdependencies, QByteArray scontent, QString sdescription, QString stype="py", QString smodel_file_name="", int ipublic=0, QString scommit="");
    QString create_model(QString smodel_name, QString smodel_class, QString sdependencies, QByteArray scontent, QString sdescription, QString stype="py", QString smodel_file_name="", int ipublic=0, QString scommit="");
    QString delete_model(QString smodel_id);
    QString grant_model(QString smodel_id, QString semail, int role);
    QString list_model_user(QString smodel_id);
    QString delete_model_user(QString smodel_id, QString sgrant_id);
    QString change_model_public(QString smodel_id, int ipublic);

    QString list_dataset();
    QString list_dataset_grant();
    QString list_dataset_public();
    QString list_dataset_available();
    QString get_dataset(QString sdataset_id);
    QString edit_dataset(QString sdataset_id, QString sdataset_name, QString sdescription, int ipublic=0);
    QString create_dataset(QString sdataset_name, QString sdataset_path, QString sdescription, int ipublic=0);
    QString delete_dataset(QString sdataset_id);
    QString grant_dataset(QString sdataset_id, QString semail, int role);
    QString list_dataset_user(QString sdataset_id);
    QString delete_dataset_user(QString sdataset_id, QString sgrant_id);
    QString change_dataset_public(QString smodel_id, int ipublic);

    QString list_trainjob();
    QString get_trainjob(QString trainjob_id);
    QString create_trainjob(QString strain_dataset_id, QString sval_dataset_id, QString smodel_id, QString sname, QString sdescription, QString budget, QString train_args, int nversion);
    QString stop_trainjob(QString trainjob_id, QString status);

    QString list_application();
    QString get_application(QString sapp_id);
    QString create_application(QString sname, QString strainjob_id, QString sdescription);
    QString stop_application(QString sapp_id, QString status);
    QString restart_application(QString sapp_id);

    QString get_computer_source();

    QString search_email(QString str);
private:
    QString m_url = "http://localhost:7777";
    QString m_token = "";
public slots:
    void setConfig(QString token);

public:
    static int RSAEncryptString(QString smsg, QString &sencrypt);
    //void GenerateRSAKey(unsigned int keyLength, QString decFilename, QString encFilename, QString seed);
};

#endif // CAICLIENT_H
